/*
 * Project it.battlehorse.rcp.tools.log
 * Created on Nov 19, 2005
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * A copy of the LGPL is available also at
 * http://www.gnu.org/copyleft/lesser.html
 * 
 */ 
package it.battlehorse.rcp.tools.log.internal;

import it.battlehorse.rcp.tools.commons.Severity;
import it.battlehorse.rcp.tools.log.LogActivator;

import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * The prefence page about the logging level and other log settings.
 * By subclassing <samp>FieldEditorPreferencePage</samp>, we
 * can use the field support built into JFace that allows
 * us to create a page that is small and knows how to 
 * save, restore and apply itself.
 * <p>
 * This page is used to modify preferences only. They
 * are stored in the preference store that belongs to
 * the main plug-in class. That way, preferences can
 * be accessed directly via the preference store.
 * 
 * @author battlehorse
 * @since Nov 19, 2005
 */
public class LogPreferencePage extends FieldEditorPreferencePage implements
		IWorkbenchPreferencePage {
	
	private RadioGroupFieldEditor logLevelField;

	public LogPreferencePage() {
		super(GRID);
		setPreferenceStore(LogActivator.getDefault().getPreferenceStore());
		setDescription("Set the Log preferences:");
	}
	
	/**
	 * Creates the field editors. Field editors are abstractions of
	 * the common GUI blocks needed to manipulate various types
	 * of preferences. Each field editor knows how to save and
	 * restore itself.
	 */
	@Override
	public void createFieldEditors() {
		
		String[][] labelsAndValues = new String[][] {
			     {Severity.TRACE.getMessage(), Severity.TRACE.getMessage()},
			     {Severity.INFO.getMessage(), Severity.INFO.getMessage()},
			     {Severity.WARNING.getMessage(), Severity.WARNING.getMessage()},
			     {Severity.ERROR.getMessage(), Severity.ERROR.getMessage()}
			     };
		
		logLevelField = new RadioGroupFieldEditor(
				"LogPreferences.LogLevel",
				"Specify the desired log level",
				1,
				labelsAndValues,
				getFieldEditorParent(),
				true);
		addField(logLevelField);		
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
	 */
	public void init(IWorkbench workbench) {}	

}
